import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
// import { h } from 'vue';
// import { Tag } from 'ant-design-vue';
import { getDictTypeListApi } from '/@/api/admin/dict';
import { getUserListByPage } from '/@/api/admin/user';
import { DICT } from '/@/enums/dict';

export const columns: BasicColumn[] = [
  {
    title: '部门名称',
    dataIndex: 'name',
    // width: 220,
    align: 'left',
  },
  {
    title: '排序',
    dataIndex: 'weight',
    // width: 100,
  },
  {
    title: '部门编码',
    dataIndex: 'deptCode',
    // width: 220,
  },

  // {
  //   title: '状态',
  //   dataIndex: 'status',
  //   width: 80,
  //   customRender: ({ record }) => {
  //     const status = record.status;
  //     const enable = ~~status === 0;
  //     const color = enable ? 'green' : 'red';
  //     const text = enable ? '启用' : '停用';
  //     return h(Tag, { color: color }, () => text);
  //   },
  // },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    // width: 220,
  },
  // {
  //   title: '备注',
  //   dataIndex: 'remark',
  // },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'deptName',
    label: '部门名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  // {
  //   field: 'status',
  //   label: '状态',
  //   component: 'Select',
  //   componentProps: {
  //     options: [
  //       { label: '启用', value: '0' },
  //       { label: '停用', value: '1' },
  //     ],
  //   },
  //   colProps: { span: 8 },
  // },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '部门名称',
    component: 'Input',
    required: true,
    colProps: {
      span: 12,
    },
  },
  {
    field: 'parentId',
    label: '上级部门',
    component: 'TreeSelect',
    required: true,
    componentProps: {
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
    colProps: {
      span: 12,
    },
  },
  {
    label: '部门编码',
    field: 'deptCode',
    component: 'Input',
    required: true,
    colProps: {
      span: 12,
    },
  },
  {
    field: 'sortOrder',
    label: '排序',
    component: 'InputNumber',
    required: true,
    colProps: {
      span: 12,
    },
  },
  {
    field: 'enable',
    label: '启用状态',
    component: 'ApiRadioGroup',
    defaultValue: 1,
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.ENABLE_STATUS,
      },
    },
    required: true,
    colProps: {
      span: 12,
    },
  },
  {
    label: '部门等级',
    field: 'deptLevel',
    component: 'ApiSelect',
    colProps: {
      span: 12,
    },
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.DEPT_LEVEL,
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'deptType',
    component: 'ApiSelect',
    label: '部门类型',
    required: true,
    colProps: {
      span: 12,
    },
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.DEPT_TYPE,
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    label: '部门主管',
    field: 'deptPrin',
    component: 'ApiSelect',
    colProps: {
      span: 12,
    },
    componentProps: {
      api: getUserListByPage,
      resultField: 'records',
      labelField: 'username',
      valueField: 'userId',
      getPopupContainer: () => document.body,
    },
  },
];
